#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/3/2 9:07
# ===========================================
#       题目名称： 27. 移除元素
#       题目地址： https://leetcode.cn/problems/remove-element/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution:
    def removeElement(self, nums, val):
        p = 0
        while p < len(nums):
            if nums[p] == val:
                del nums[p]
            else:
                p += 1
        return len(nums)


if __name__ == "__main__":
    s = Solution()
    print("nums = [3,2,2,3], val = 3  => ", s.removeElement(nums=[3, 2, 2, 3], val=3))  # 2
    print("nums = [0,1,2,2,3,0,4,2], val = 2 => ", s.removeElement(nums=[0, 1, 2, 2, 3, 0, 4, 2], val=2))  # 5
